import tensorflow as tf
import numpy as np
from supervised_vgg16 import super_vgg16
from supervised_vgg16 import data_preprocessing,prepare_data

#加载方法1：
image = tf.placeholder(tf.float32,[None,32,32,3],name='input_x')
y_ = tf.placeholder(tf.float32,[None,10],name='input_y')
train_flag =  tf.placeholder(tf.bool,name='fll')
keep_prob = tf.placeholder(tf.float32,name='prob')
loss,logits = super_vgg16(image,y_,keep_prob,train_flag)
saver = tf.train.Saver()

with tf.name_scope("accuracy"):
    correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(y_, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
#
#加载方法2：
# saver = tf.train.import_meta_graph("./vgg_model/model.ckpt.meta")
# graph = tf.get_default_graph()
# image = graph.get_tensor_by_name("input/x_input:0")
# keep_prob = graph.get_tensor_by_name("input/keep_prob:0")
# train_flag = graph.get_tensor_by_name("input/train_flag:0")
# logits = graph.get_tensor_by_name("fc33/Relu:0")

with tf.Session() as sess:
    saver.restore(sess,tf.train.latest_checkpoint('./supervised_vgg16_model'))
    print("finish loading model!")
    train_x , train_y , test_x ,test_y = prepare_data()
    train_x , test_x = data_preprocessing(train_x,test_x)
#
    # images = test_x[10].reshape(1,32,32,3)
    # label = sess.run(logits,feed_dict={image:images,keep_prob:1.0,train_flag:False})
    # print(np.argmax(label))
    # print(np.argmax(test_y[10]))
    per_dataset = np.load("./target_dataset/target_2_CW_supervised_vgg16.npy")
    acc = sess.run(accuracy,feed_dict={image:per_dataset,y_:test_y[0:1000],keep_prob:1.0,train_flag:False})
    print(str(acc))

